<?php
    $libraryCardNo = $_GET['libraryCardNo'];
    $libraryNo = $_COOKIE['libraryNo'];

    require('db_connection.php');
    $sql = "SELECT * FROM tblclient WHERE libraryCardNo = '$libraryCardNo'";
    $result1 = mysql_query($sql);
    while ($row = mysql_fetch_array($result1))
    {
      $libraryCardNo =$row['libraryCardNo'];
      $lastName = $row['lastName'];
      $firstName = $row['firstName'];
      $middleName = $row['middleName'];
      $address = $row['address'];
      $contactNo = $row['contactNo'];
      $schoolorg = $row['schoolorg'];
      $email = $row['email'];
    }

    //$category = $_POST['category'];
    $searchtext = $_POST['searchtext'];
        require('db_connection.php');
        $query = "SELECT * FROM tblcollection WHERE accessionNo LIKE '%$searchtext' AND libraryNo='$libraryNo'";
        $result1 = mysql_query($query);

?>
<!doctype html public "-//W3C//DTD HTML 4.01//EN">

<html>

   <head>
      <title>Circulation</title>
      <meta http-equiv="generator" content="PHP Designer 2005" />
      <style type="text/css">
        @import url(style.css);
      </style>
   </head>

   <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000" class=''>
   
   <script LANGUAGE=javascript>
   function check()
     {
        if(document.search_form.searchtext.value=="")
        {
          alert('Enter Call No.');
          return false;
        }
        return true;
     }
    </script>

    <?php echo "<form name='search_form' method='post' action='borrowsearch.php?libraryCardNo=$libraryCardNo' onSubmit='return check();'>";?>
    <table width='80%' align='center' class='content'>
        <tr><td colspan='2'><img src='images/banner.jpg' /></td></tr>
            <tr><td align='right' colspan='2' class='logout'><?php require ('loginout.php');?></td></tr>
        <tr><td>
            <table align='left' width='40%' class='bodyborder'>
<tr class='tools'><td><a href='bookborrowed.php'>Books Borrowed</a> | <a href='bookreserved.php'>Books Reserved</a></td>
                </tr>
            </table>
            <table align='right' width='60%' class='bodyborder'>
                <?php
             $userType = $_COOKIE['userType'];
                if($userType=='superadministrator')
                {
                    echo "<tr class='tools'><td align='right'><a href='circulation.php'>Circulation</a> | <a href='reservematerial.php?libraryCardNo=$libraryCardNo'>Reserve</a> |<a href='deletereservation.php?libraryCardNo=$libraryCardNo'> Cancel Reservation </a>| <a href='borrowmaterial.php?libraryCardNo=$libraryCardNo'>Borrow</a>|  <a href='return.php?libraryCardNo=$libraryCardNo'>Return</a> |<a href='mainsad.php'>Home</a></td>";
                }
                else
                {
                    echo "<tr class='tools'><td align='right'><a href='circulation.php'>Circulation</a> | <a href='reservematerial.php?libraryCardNo=$libraryCardNo'>Reserve</a> |<a href='deletereservation.php?libraryCardNo=$libraryCardNo'> Cancel Reservation</a> | <a href='borrowmaterial.php?libraryCardNo=$libraryCardNo'>Borrow</a>|  <a href='return.php?libraryCardNo=$libraryCardNo'>Return</a> |<a href='main.php'>Home</a></td>";
                }

             ?>
                </tr>
            </table>
            </td>
        </tr>
        <tr><td height='30'></td></tr>
        <tr><td>
            <table align='center' cellpadding='0' width='50%' class='bodyborder'>
                <tr>
                <?php echo"<tr><td align='center' colspan='2'><b><font size='4'>$firstName $middleName $lastName</font></b></td></tr>";
                      echo "<tr class='td1'><td align='right'>Library Card No.:<td> <b>$libraryCardNo</b></td></td></tr>";
                      echo "<tr class='td2'><td align='right'>Address:<td><b> $address </b></td></tr>";
                      echo "<tr class='td1'><td align='right'>School or Organization:<td><b> $schoolorg </b></td></tr>";
                      echo "<tr class='td2'><td align='right'>Contact No:<td> <b>$contactNo</b></td></tr>"; ?>
                </tr>
            </table>
            </td>
        </tr>
        <tr><td height='30'></td></tr>
        <tr>
            <td>
            <table align='center'>
                <tr><td>Accession No.</td>
                    <td><input type='text' name='searchtext' size='20'></td>
                    <td><input type='submit' value='OK' class='tool'></td>
                </tr>

            </table>
            </form>
            <table align='center' width='60%' cellspacing='0' cellpadding='3'>
            <tr><td height='30'></td></tr>
            <tr><th colspan='2'>Search Result</th></td>
            <tr><td height='30'></td></tr>
            
<?php
            /*
$ctr=1;
                while ($row = mysql_fetch_array($result1))
                {
                    //echo "<tr><td></td></tr>";
                    $title=$row['title'];
                    $author = $row['author'];
                    $publisher = $row['publisher'];
                    $materialID = $row['materialID'];

                    echo "<form method='post' action='borrow.php?libraryCardNo=$libraryCardNo&materialID=$materialID'>";
                    echo"<tr class='td1'><td colspan='2'>".$ctr."&nbsp;&nbsp;".$title."</td></tr>";
                    echo"<tr class='td2'><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by &nbsp;".$author.", ".$publisher."</td><td><input type='submit' value='Borrow' class='tool'></td></tr>";
                    //echo"</tr>";
                    echo "</form>";
                    $ctr++;
                }
*/
            ?>

            <?php
            $libraryNo = $_COOKIE['libraryNo'];
            $ctr=1;

                while ($row = mysql_fetch_array($result1))
                {

                    //echo "<tr><td></td></tr>";
                    $title=$row['title'];
                    $author = $row['author'];
                    $publisher = $row['publisher'];
                    $materialID = $row['materialID'];
                    $copyNo = $row['copyNo'];
                    
                        //require('db_connection.php');

                        $sql2 = "SELECT * FROM tblcirculation WHERE materialID='$materialID' AND libraryNo='$libraryNo'";
                        $result2 = mysql_query($sql2);
                        $ctr2 = mysql_num_rows($result2);
                    if($copyNo == $ctr2)
                    {
                        $dis="disabled='disabled' value='Not Available'";
                    }
                    else
                    {
                        $dis="enabled='enabled' value='Borrow'";
                    }
                    
                    echo "<form method='post' action='borrow.php?libraryCardNo=$libraryCardNo&materialID=$materialID'>";
                    echo"<tr class='td1'><td colspan='2'>".$ctr."&nbsp;&nbsp;".$title."</td></tr>";
                    echo"<tr class='td2'><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by &nbsp;".$author.", ".$publisher."</td><td><input type='submit'   $dis class='tool'></td></tr>";
                    //echo"</tr>";
                    echo "</form>";
                    $ctr++;
                }
            ?>
            </table>
            </td>
        </tr>
        <tr><td height='30'></td></tr>
        <tr><td align='center' colspan='2'><?php require ('copyright.php')?></td></tr>
    </table>
   </body>
</html>
